{% macro preview_story_card(story) %}
  <div class="card card-border bg-base-100 mx-4 my-2">
    <div class="card-body">
      <h2 class="card-title">{{ story.title }}</h2>
      <p>{{ story.content }}</p>
      <div class="card-actions"></div>
    </div>
  </div>
{% endmacro %}

{% macro analyze_story_card(story, used_story_ids, form_action, other_ids) %}
  {% set is_used = story.id in used_story_ids %}
  {% set card_classes = ["card", "card-bordered", "bg-base-200", "mx-4", "my-2", "shadow-sm", "transition-shadow", "duration-200", "hover:shadow-lg"] %}
  {% if is_used %}
    {% set card_classes = card_classes + ["border-success/60", "ring-1", "ring-success/30"] %}
  {% elif story.important %}
    {% set card_classes = card_classes + ["border-warning/60", "ring-1", "ring-warning/30"] %}
  {% else %}
    {% set card_classes = card_classes + ["border-base-300"] %}
  {% endif %}

  <article class="{{ ' '.join(card_classes) }}">
    <div class="card-body p-4 flex flex-col gap-4 flex-row items-start">
      <div class="flex-1 space-y-3">
        <div class="flex flex-col gap-2 flex-row items-start justify-between">
          <a class="text-lg link link-base" href="{{ url_for('assess.story', story_id=story.id) }}">{{ story.title }}</a>
          {% if is_used %}<span class="badge badge-success badge-xs badge-outline whitespace-nowrap">Used in attributes</span>{% endif %}
        </div>
        <div class="flex flex-col gap-2 flex-row items-start justify-between">
          {% if story.links %}
            <a href="{{ story.links[0] }}"
               target="_blank"
               rel="noopener"
               class="link link-primary text-xs inline-flex items-center gap-1 w-fit"
               data-testid="story-link-{{ story.id }}">
              {{ heroicon_mini("arrow-top-right-on-square") }}
              <span>{{ story.links[0] }}</span>
            </a>
          {% endif %}
          <button type="button"
                  class="btn btn-sm btn-outline"
                  data-testid="remove-story-{{ story.id }}"
                  {{ form_action }}
                  hx-vals='{"stories[]": {{ other_ids | tojson }} }'
                  hx-target="#report"
                  hx-target-error="#report">
            Remove from report
          </button>
          {% if story.summary %}<p class="text-sm leading-relaxed text-base-content/70 whitespace-pre-line">{{ story.summary }}</p>{% endif %}
        </div>
      </div>
    </div>
  </article>
{% endmacro %}
